package ui.activity.mine;
import adapter.DeliveryAreaDetailAdapter;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import base.BaseBean;
import base.activity.BaseLayoutActivity;
import bean.AreaDetailBean;
import bean.SchoolAreaBean;
import bean.SchoolBean;
import bean.TestBean;
import com.dispatchapp.andlei.R;
import netWork.NetUtils;
import utils.GsonUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 配送区域详情
 *
 * @author Andlei
 * @DATE 2019/1/21
 */
public class DeliveryAreaDetailActivity extends BaseLayoutActivity {
    private List<AreaDetailBean> list = new ArrayList<>();
    private DeliveryAreaDetailAdapter adapter;
    private RecyclerView recyclerView;
    private TextView tv_school_name;
    private String area_id;
    private String school_name;
    private NetUtils netUtils;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("配送区域");
    }
    @Override
    protected int getLayoutId() {
        return R.layout.activity_delivery_area_detail;
    }

    @Override
    protected void findViews() {
        netUtils = new NetUtils(mActivity,netRequestCallBack);
        tv_school_name = getView(R.id.tv_schoolname);
        recyclerView = getView(R.id.list_rcy);
//        for(int i = 0; i<10;i++){
//           TestBean bean  = new TestBean();
//           bean.str = i+"号楼";
//           if(i==5){
//               bean.isSelect = true;
//           }
//           list.add(bean);
//       }
    }

    @Override
    protected void formatViews() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
        layoutManager.setOrientation(LinearLayout.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new DeliveryAreaDetailAdapter(R.layout.item_delivert_area_detail,list);
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void formatData() {
        tv_school_name.setText(school_name);
        Map<String,Object> map = new HashMap<>();
        map.put("area_id",area_id+"");
        netUtils.get("rider/user/area-detail",map,BaseBean.class,null,false);
    }

    @Override
    protected void getBundle(Bundle bundle) {
        area_id = bundle.getString("school_id");
        school_name = bundle.getString("name");
    }

    @Override
    public void onClick(View view) {

    }
    private NetUtils.NetRequestCallBack netRequestCallBack = new NetUtils.NetRequestCallBack() {
        @Override
        public void error(String action, Throwable e, Map tag) {

        }

        @Override
        public void success(String action, BaseBean t, Map tag) {
            list = GsonUtils.getInstance(mActivity).parseNoHeaderJArray(t, AreaDetailBean.class);
            adapter.setNewData(list);
        }
    };
}
